package com.hunan.chinamobile.service.impl;

import com.hunan.chinamobile.dao.BaseStationMapper;
import com.hunan.chinamobile.dto.BaseStationDTO;
import com.hunan.chinamobile.dto.BaseStationInfoDTO;
import com.hunan.chinamobile.model.BaseStation;
import com.hunan.chinamobile.service.BaseStationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;

@Service
public class BaseStationServiceImpl implements BaseStationService {

    @Resource
    private BaseStationMapper baseStationMapper;

    @Override
    public void save(BaseStation model) {
        baseStationMapper.insert(model);
    }

    @Override
    public void deleteById(String id) {
        baseStationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(BaseStation model) {
        baseStationMapper.updateByPrimaryKeySelective(model);
    }

    @Override
    public BaseStation findById(String id) {
        return baseStationMapper.selectByPrimaryKey(id);
    }

    @Override
    public BaseStation check(String bsName) {
        return baseStationMapper.check(bsName);
    }

    @Override
    public List<BaseStationDTO> findList(String cityId, String bsName) {
        return baseStationMapper.findList(cityId, bsName);
    }

    @Override
    public List<BaseStation> findAll() {
        List<BaseStation> bss = baseStationMapper.selectAll();
        if(bss != null)
            bss.sort(Comparator.comparing(BaseStation::getCreatedAt));
        return bss;
    }

    @Override
    public List<BaseStation> findByCityId(String cityId) {
        return baseStationMapper.findByCityId(cityId);
    }

    @Override
    public List<BaseStationInfoDTO> findByException(String cityId,String bsName, Boolean ok) {
        return baseStationMapper.findByException(cityId,bsName, ok);
    }

    @Override
    public BaseStationDTO findDTOById(String bsId) {
        return baseStationMapper.findDTOById(bsId);
    }
}
